// ActionScript file
import com.octlan.wbcompare.PageBoxVO;
import com.octlan.wbcompare.base.Constants;
import com.octlan.wbcompare.ctrl.MainCtrl;
import com.octlan.wbcompare.event.PageLoadEvent;
import com.octlan.wbcompare.util.PageBoxHelper;
import com.octlan.wbcompare.util.XMLHelper;

import flash.net.URLVariables;

import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;


private function getData():void
{
    var ctrl:MainCtrl = MainCtrl.getInstance();
    var service:HTTPService = ctrl.createService();
    service.url = Constants.SERVER_URI;
    service.addEventListener(ResultEvent.RESULT, onDataResult);

    var paras:URLVariables = new URLVariables();
    paras.catalog = 'country';
    paras.per_page = 300;
    paras.page = 1;

    service.send(paras);

}
private function onDataResult(event:ResultEvent):void
{
    var str:String = event.result.toString();
    var info:XML = XMLHelper.removeNamespaceURI(str);
    var vo:PageBoxVO = PageBoxHelper.getPageBoxVO(info);
    pageBox.setPage(vo.page);
    pageBox.setPages(vo.pages);
    pageBox.setLpp(vo.per_page);
    pageBox.setLTotal(vo.total);
    pageBox.updateButtonState();

    datalist = info.children();
    //trace(datalist);
}

private function onPageLoad(event:PageLoadEvent):void
{

    var ctrl:MainCtrl = MainCtrl.getInstance();
    var service:HTTPService = ctrl.createService();
    service.url = Constants.SERVER_URI;
    service.addEventListener(ResultEvent.RESULT, onDataResult);

    var paras:URLVariables = new URLVariables();
    paras.catalog = 'country';
    paras.per_page = event.lpp;
    paras.page = event.page;

    service.send(paras);
}
